/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;


/**
 *
 * @author Administrator
 */
public class sqlite_test {
    public static ResultSet doget()throws Exception{
        Class.forName("org.sqlite.JDBC");
        Connection conn =DriverManager.getConnection("jdbc:sqlite:my.db");
        Statement stat = conn.createStatement();
//        int i=stat.executeUpdate("drop table if exists people;");
//        stat.executeUpdate("create table people (name nvarchar(15), occupation nvarchar(15),mydate date);");
//        stat.execute("insert into people values ('明明','computer',1231241231)");
//        stat.executeUpdate("update people set occupation='kkkalaka' where name='明明'");
//        PreparedStatement prep = conn.prepareStatement("insert into people values (?,?,?);");
//        prep.setString(1, "会好");
//        prep.setString(2, "politics");
////        prep.setDate(3, new Date(System.currentTimeMillis()));
//        prep.setDate(3, new Date(System.currentTimeMillis()));
//        prep.addBatch();
//        prep.setString(1, "明瑞");
//        prep.setString(2, "computers");
//        prep.setDate(3, new Date(System.currentTimeMillis()));
//        prep.addBatch();
//        prep.setString(1, "Wittgenstein");
//        prep.setString(2, "smartypants");
//        prep.setDate(3, new Date(System.currentTimeMillis()));
//        prep.addBatch();
//        conn.setAutoCommit(false);
//        prep.executeBatch();
//        conn.setAutoCommit(true);

        ResultSet rs = stat.executeQuery("select * from gongzuomian;");
        while (rs.next()) {
          System.out.println("name = " + rs.getString("mingcheng"));
          System.out.println("job = " + rs.getString("zhitu"));
//          System.out.println("date="+rs.getLong(3));
          Timestamp date=new Timestamp(rs.getLong(3));
          System.out.println(date.toString());
        }
        rs.close();
        conn.close();
        return rs;
    }
    public static void main(String args[]) throws Exception{
//        ResultSet rs = doget();
//        while (rs.next()) {
//          System.out.println("name = " + rs.getString("name"));
//          System.out.println("job = " + rs.getString("occupation"));
//          System.out.println("date="+rs.getTime(3)+" "+rs.getDate(3));
//        }

        File file=new File("haha.txt");
        String str=file.getAbsolutePath();
        String strnew=str.replaceAll(file.getName(), "");
        System.out.println(strnew);
    }
    
}
